home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / isys.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  5.3 KB  |  242 lines

  1. import kudzu
  2. import _isys
  3. import string
  4. import os
  5.  
  6. def spaceAvailable(device, fsystem = "ext2"):
  7.     makeDevInode(device, "/tmp/spaceDev")
  8.     mount("/tmp/spaceDev", "/mnt/space", fstype = fsystem)
  9.     space = _isys.devSpaceFree("/mnt/space/.")
  10.     umount("/mnt/space")
  11.     os.rmdir("/mnt/space")
  12.     os.remove("/tmp/spaceDev")
  13.     return space
  14.  
  15. def raidstop(mdDevice):
  16.     makeDevInode(mdDevice, "/tmp/md")
  17.     fd = os.open("/tmp/md", os.O_RDONLY)
  18.     os.remove("/tmp/md")
  19.     _isys.raidstop(fd)
  20.     os.close(fd)
  21.  
  22. def raidstart(mdDevice, aMember):
  23.     makeDevInode(mdDevice, "/tmp/md")
  24.     makeDevInode(aMember, "/tmp/member")
  25.     fd = os.open("/tmp/md", os.O_RDONLY)
  26.     os.remove("/tmp/md")
  27.     _isys.raidstart(fd, "/tmp/member")
  28.     os.close(fd)
  29.     os.remove("/tmp/member")
  30.  
  31. def raidsb(mdDevice):
  32.     makeDevInode(mdDevice, "/tmp/md")
  33.     fd = os.open("/tmp/md", os.O_RDONLY)
  34.     rc = _isys.getraidsb(fd)
  35.     os.close(fd)
  36.     return rc
  37.  
  38. def losetup(device, file):
  39.     loop = os.open(device, os.O_RDONLY)
  40.     targ = os.open(file, os.O_RDWR)
  41.     _isys.losetup(loop, targ, file)
  42.     os.close(loop)
  43.     os.close(targ)
  44.  
  45. def unlosetup(device):
  46.     loop = os.open(device, os.O_RDONLY)
  47.     _isys.unlosetup(loop)
  48.     os.close(loop)
  49.  
  50. def ddfile(file, megs):
  51.     fd = os.open(file, os.O_RDWR | os.O_CREAT)
  52.     _isys.ddfile(fd, megs)
  53.     os.close(fd)
  54.  
  55. def mount(device, location, fstype = "ext2"):
  56.     return _isys.mount(fstype, device, location)
  57.  
  58. def umount(what):
  59.     return _isys.umount(what)
  60.  
  61. def smpAvailable():
  62.     return _isys.smpavailable()
  63.  
  64. def chroot (path):
  65.     return _isys.chroot (path)
  66.  
  67. def checkBoot (path):
  68.     return _isys.checkBoot (path)
  69.  
  70. def swapoff (path):
  71.     return _isys.swapoff (path)
  72.  
  73. def swapon (path):
  74.     return _isys.swapon (path)
  75.  
  76. def fbconProbe(path):
  77.     return _isys.fbconprobe (path)
  78.  
  79. def loadFont(font):
  80.     return _isys.loadFont (font)
  81.  
  82. def loadKeymap(keymap):
  83.     return _isys.loadKeymap (keymap)
  84.  
  85. def probePciDevices():
  86.     # probes all probeable buses and returns a list of 
  87.     # ( driver, major, minor, description, args ) tuples, where args is a
  88.     # list of (argName, argDescrip) tuples
  89.     devices = _isys.pciprobe()
  90.     if (not devices): return None
  91.  
  92.     result = []
  93.     for dev in devices:
  94.     info = _isys.findmoduleinfo(dev)
  95.     if not info:
  96.         raise KeyError, "module " + dev + " is not in the module list"
  97.     result.append(info)
  98.  
  99.     return result
  100.  
  101. def driveDict(klassArg):
  102.     p = _isys.ProbedList()
  103.     p.updateIde()
  104.     p.updateScsi()
  105.  
  106.     dict = {}
  107.     for (klass, dev, descr) in p:
  108.     if (klass == klassArg):
  109.         dict[dev] = descr
  110.     return dict
  111.  
  112. def hardDriveDict():
  113.     return driveDict("disk")
  114.  
  115. def floppyDriveDict():
  116.     return driveDict("floppy")
  117.  
  118. def cdromList():
  119.     list = driveDict("cdrom").keys()
  120.     list.sort()
  121.     return list
  122.  
  123. def moduleListByType(type):
  124.     return _isys.modulelist(type)
  125.  
  126. def makeDevInode(name, fn):
  127.     return _isys.mkdevinode(name, fn)
  128.  
  129. def inet_ntoa (addr):
  130.     return "%d.%d.%d.%d" % ((addr >> 24) & 0x000000ff,
  131.                             (addr >> 16) & 0x000000ff,
  132.                             (addr >> 8) & 0x000000ff,
  133.                             addr & 0x000000ff)
  134.     
  135. def inet_aton (addr):
  136.     quad = string.splitfields (addr, ".")
  137.     try: 
  138.         rc = ((string.atoi (quad[0]) << 24) +
  139.               (string.atoi (quad[1]) << 16) +
  140.               (string.atoi (quad[2]) << 8) +
  141.               string.atoi (quad[3]))
  142.     except IndexError:
  143.         raise ValueError
  144.     return rc
  145.  
  146. def inet_calcNetmask (ip):
  147.     if isinstance (ip, type (0)):
  148.         addr = inet_ntoa (ip)
  149.     else:
  150.         addr = ip
  151.     quad = string.splitfields (addr, ".")
  152.     if len (quad) > 0:
  153.         klass = string.atoi (quad[0])
  154.         if klass <= 127:
  155.             mask = "255.0.0.0";
  156.         if klass <= 191:
  157.             mask = "255.255.0.0";
  158.         else:
  159.             mask = "255.255.255.0";
  160.     return mask
  161.     
  162. def inet_calcNetBroad (ip, nm):
  163.     if isinstance (ip, type ("")):
  164.         ipaddr = inet_aton (ip)
  165.     else:
  166.         ipaddr = ip
  167.  
  168.     if isinstance (nm, type ("")):
  169.         nmaddr = inet_aton (nm)
  170.     else:
  171.         nmaddr = nm
  172.  
  173.     netaddr = ipaddr & nmaddr
  174.     bcaddr = netaddr | (~nmaddr);
  175.             
  176.     return (inet_ntoa (netaddr), inet_ntoa (bcaddr))
  177.  
  178. def inet_calcGateway (bc):
  179.     if isinstance (bc, type ("")):
  180.         bcaddr = inet_aton (bc)
  181.     else:
  182.         bcaddr = ip
  183.  
  184.     return inet_ntoa (bcaddr - 1)
  185.  
  186. def inet_calcNS (net):
  187.     if isinstance (net, type ("")):
  188.         netaddr = inet_aton (net)
  189.     else:
  190.         netaddr = net
  191.  
  192.     return inet_ntoa (netaddr + 1)
  193.  
  194. def parseArgv(str):
  195.     return _isys.poptParseArgv(str)
  196.  
  197. def getopt(*args):
  198.     return apply(_isys.getopt, args)
  199.  
  200. def compareDrives(first, second):
  201.     type1 = first[0:3]
  202.     type2 = second[0:3]
  203.  
  204.     if type1 == "hda":
  205.     type1 = 0
  206.     elif type1 == "sda":
  207.     type1 = 1
  208.     else:
  209.     type1 = 2
  210.  
  211.     if type2 == "hda":
  212.     type2 = 0
  213.     elif type2 == "sda":
  214.     type2 = 1
  215.     else:
  216.     type2 = 2
  217.  
  218.     if (type1 < type2):
  219.     return -1
  220.     elif (type1 > type2):
  221.     return 1
  222.     elif first < second:
  223.     return -1
  224.     elif first > second:
  225.     return 1
  226.  
  227.     return 0
  228.  
  229. def configNetDevice(device, ip, netmask, gw):
  230.     return _isys.confignetdevice(device, ip, netmask, gw)
  231.  
  232. def resetResolv():
  233.     return _isys.resetresolv()
  234.  
  235. def setResolvRetry(count):
  236.     return _isys.setresretry(count)
  237.  
  238. def pumpNetDevice(device):
  239.     # returns None on failure, "" if no nameserver is found, nameserver IP
  240.     # otherwise
  241.     return _isys.pumpnetdevice(device)
  242.